package com.hccl.mongoEntities.action;

import DM.StateMachine;
import entities.step.Step;

import java.util.Map;

/**
 * Created by xjzhang on 2017/11/17.
 */
public class ExecuteStepAction extends Action{

    public ExecuteStepAction(){
        super();
    }

    @Override
    public void run(StateMachine stateMachine) throws Exception{
        try {
            onEnter(stateMachine);
            //拿到参数别表中指定的名字的step，然后run
            if (stateMachine == null || stateMachine.getCurrentProcess() == null)
                throw new Exception("当前的process为空！");
            Map<String,Step> stepMap = stateMachine.getCurrentProcess().getStepMap();
            if (stepMap == null)
                throw new Exception("当前的process没有stepMap");
            Step step = stepMap.get(actionParams.get(0));
            if (step == null)
                throw new Exception("当前的process没有要跳转的step");
            step.run(stateMachine);

        }finally {
            onExit(stateMachine);
        }

    }


}
